USE [DemoGraphics]
GO

/****** Object:  StoredProcedure [dbo].[InsertRecord]    Script Date: 06/03/2010 17:57:18 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



-- This Stored Procedure gets a value according State, Race, Couple, Field from table specified by @table_name
CREATE PROCEDURE [dbo].[GetValue]
 @table_name VARCHAR(100),
 @state VARCHAR(2),
 @race VARCHAR(4),
 @couple VARCHAR(3),
 
 @field VARCHAR(25)
AS
	DECLARE @SQL varchar(255)
	
	-- This generates the SQL that returns the value
		SET @SQL = 'SELECT Value FROM ' + @table_name + ' WHERE State = '''
		SET @SQL = @SQL + @state + ''' AND  Race = '''
		
		SET @SQL = @SQL + @race + ''' AND Couple = '''
		SET @SQL = @SQL + @couple + ''' AND Field = '''
		SET @SQL = @SQL + @field+ ''' '
				
		-- SELECT 'SQL' = @SQL
		
		
		-- Execute the SQL
		EXECUTE (@SQL)
		

GO


